/**
 * 
 */
package com.hp.bon.sgw.domain;

import java.util.LinkedList;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.hp.ocs.diameter.message.dictionary.AvpType;

/**
 * 限流规则
 */
@Entity
@Table(name = "T_Flux_Ctrl_By_Key_RULE")
public class FluxCtrlByKeyRule {
	
	private int id;
	private String capability;//能力名称
	private String key;//识别业务关键字，例如转售商ID
	private String xmlTag;//字段提取路径（XPATH表示）
	private int period;//限流周期，单位秒
	private int max;//周期内的限流条数
	private int ret;//拒绝结果码
	private int counter;//非配置表字段，周期内的计数器
	private long resetTime;//非配置表字段，重置时间

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getCapability() {
		return capability;
	}

	public void setCapability(String capability) {
		this.capability = capability;
	}
	
	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public int getPeriod() {
		return period;
	}

	public void setPeriod(int period) {
		this.period = period;
	}

	@Column(name="LIMIT_MAX")
	public int getMax() {
		return max;
	}

	public void setMax(int max) {
		this.max = max;
	}
	
	@Transient
	public int getCounter() {
		return counter;
	}

	public void setCounter(int counter) {
		this.counter = counter;
	}

	@Column(name="XML_TAG")
	public String getXmlTag() {
		return xmlTag;
	}

	public void setXmlTag(String xmlTag) {
		this.xmlTag = xmlTag;
	}

	public int getRet() {
		return ret;
	}

	public void setRet(int ret) {
		this.ret = ret;
	}
	//XML path convert to AVP path
	private LinkedList<AvpType> keyAvpPath = new LinkedList<AvpType>();
	
	@Transient
	public LinkedList<AvpType> getKeyAvpPath() {
		return keyAvpPath;
	}

	public void setKeyAvpPath(LinkedList<AvpType> keyAvpPath) {
		this.keyAvpPath = keyAvpPath;
	}

	synchronized public void addConter() {
		this.counter++;
	}
	@Transient
	public long getResetTime() {
		return resetTime;
	}

	public void setResetTime(long resetTime) {
		this.resetTime = resetTime;
	}
	
	@Override
	public String toString() {
		return "capability:"+capability+",key:"+key+",xmlTag:"+xmlTag+",period:"+period+",max:"+max+",ret:"+ret;
	}
}
